package com.zhiyun.test.base.listener;

import com.zhiyun.test.base.controller.BaseController;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.testng.ITestContext;
import org.testng.ITestResult;
import org.testng.TestListenerAdapter;

import java.io.File;

/**
 * Created by user on 2019-5-27.
 */
public class TakePicListener extends TestListenerAdapter{
  @Override
  public void onTestSuccess(ITestResult var1){
    super.onTestSuccess(var1);
  }
  @Override
  public void onTestFailure(ITestResult var1){
    String path = System.getProperty("user.dir")+"/"+String.valueOf(System.currentTimeMillis())+".png";
    File screen = ((TakesScreenshot) ((BaseController)var1.getInstance()).webDriver).getScreenshotAs(OutputType.FILE);
    File file = new File(path);
    screen.renameTo(file);
    super.onTestFailure(var1);
  }
  @Override
  public void onTestSkipped(ITestResult var1){
    super.onTestSkipped(var1);
  }
  @Override
  public void onTestStart(ITestResult var1){
    super.onTestStart(var1);
  }
  @Override
  public void onStart(ITestContext var1){
    super.onStart(var1);
  }
  @Override
  public void onFinish(ITestContext var1){
    super.onFinish(var1);
  }
}
